﻿using MvvmLib;
using System.Collections.Generic;

namespace FeatureJudgeLib
{
    public class Vm_Feature : Vm_Base
    {
        /// <summary>
        /// 特征名称
        /// </summary>
        public string FeatureName
        {
            get { return _FeatureName; }
            set
            {
                if (_FeatureName != value)
                {
                    _FeatureName = value;
                    this.OnPropertyChanged("FeatureName");
                }
            }
        }
        private string _FeatureName;

        /// <summary>
        /// 特征值
        /// </summary>
        public double Value
        {
            get { return _Value; }
            set
            {
                if (_Value != value)
                {
                    _Value = value;
                    this.OnPropertyChanged("Value");
                }
            }
        }
        private double _Value;

        /// <summary>
        /// 判断结果
        /// </summary>
        public E_Bin Bin
        {
            get { return _Bin; }
            set
            {
                if (_Bin != value)
                {
                    _Bin = value;
                    this.OnPropertyChanged("Bin");
                }
            }
        }
        private E_Bin _Bin;

        /// <summary>
        /// 判断特征值的级别
        /// </summary>
        /// <param name="featureStdList">特征标准列表</param>
        public void Judge(List<Vm_Feature_Std> featureStdList)
        {
            if (featureStdList == null)
            {
                return;
            }

            foreach (Vm_Feature_Std featureStd in featureStdList)
            {
                //判断特征码是否相同
                if (FeatureName != featureStd.FeatureName)
                {
                    continue;
                }

                //赋值默认级别
                Bin = featureStd.DefaultBin;

                //根据条件执行不同的判断策略
                if (featureStd.Max == null)
                {
                    //上限为空
                    if (featureStd.Min != null)
                    {
                        //下限不为空
                        switch (featureStd.CompareMinType)
                        {
                            case E_CompareMinType.大于:
                                {
                                    if (Value > featureStd.Min)
                                    {
                                        Bin = featureStd.Bin;
                                    }
                                }
                                break;
                            case E_CompareMinType.大于等于:
                                {
                                    if (Value >= featureStd.Min)
                                    {
                                        Bin = featureStd.Bin;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
                else
                {
                    //上限不为空
                    if (featureStd.Min == null)
                    {
                        //下限为空
                        switch (featureStd.CompareMaxType)
                        {
                            case E_CompareMaxType.小于:
                                {
                                    if (Value < featureStd.Max)
                                    {
                                        Bin = featureStd.Bin;
                                    }
                                }
                                break;
                            case E_CompareMaxType.小于等于:
                                {
                                    if (Value <= featureStd.Max)
                                    {
                                        Bin = featureStd.Bin;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //上下限都不为空
                        switch (featureStd.CompareMinType)
                        {
                            case E_CompareMinType.大于:
                                {
                                    switch (featureStd.CompareMaxType)
                                    {
                                        case E_CompareMaxType.小于:
                                            {
                                                if (Value > featureStd.Min && Value < featureStd.Max)
                                                {
                                                    Bin = featureStd.Bin;
                                                }
                                            }
                                            break;
                                        case E_CompareMaxType.小于等于:
                                            {
                                                if (Value > featureStd.Min && Value <= featureStd.Max)
                                                {
                                                    Bin = featureStd.Bin;
                                                }
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                break;
                            case E_CompareMinType.大于等于:
                                {
                                    switch (featureStd.CompareMaxType)
                                    {
                                        case E_CompareMaxType.小于:
                                            {
                                                if (Value >= featureStd.Min && Value < featureStd.Max)
                                                {
                                                    Bin = featureStd.Bin;
                                                }
                                            }
                                            break;
                                        case E_CompareMaxType.小于等于:
                                            {
                                                if (Value >= featureStd.Min && Value <= featureStd.Max)
                                                {
                                                    Bin = featureStd.Bin;
                                                }
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }
    }
}
